package com.zhang.b_work.a_poll;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class A_producer {

    @Test
    public void test1() throws IOException, TimeoutException {
        //1.创建Connection
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.233.100");
        factory.setPort(5672);
        factory.setVirtualHost("/");
        factory.setUsername("guest");
        factory.setPassword("guest");
        Connection connection = factory.newConnection();

        //2.创建channel
        Channel channel = connection.createChannel();

        //3.创建交换机(这里使用的是默认交换机 AMQP_Default)

        //4.创建队列
        channel.queueDeclare("q2",true,false,false,null);


        //5.交换机与队列绑定(指定路由key)


        //6.发送消息
        for (int i = 1; i <= 20; i++) {
            String message = "hello boy"+i;
            channel.basicPublish("","q1",null,message.getBytes());
        }

    }
}






